﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace QqForm
{
    public class MessageDealGetQqMsg : MessageDealBase
    {
        public override object ShowMessage(TcpClass tcpClass, byte[] msg)
        {
            PostQqServerBackResult backResult = new PostQqServerBackResult();
            string cmdQq = Encoding.UTF8.GetString(msg, 0, msg.Length);
            if (cmdQq.IndexOf("VER", StringComparison.Ordinal) == -1)
            {
                return backResult;
            }
            string[] resultArrary = cmdQq.Split('&');
            string qqid = (resultArrary[7].Split('='))[1];
            string msgs = ((resultArrary[8].Split('='))[1].Split('\n'))[0].Replace("\r\n","\r\n");
            string nk = "";
            foreach (ChatFormHelper item in QqUserHelper.ChatFormHelpers)
            {
                if (item.Uid == qqid && item.State == 0)
                {
                    item.ChatForm.MsgHelper(msgs, DateTime.Now);
                    return backResult;
                }
                else if (item.Uid == qqid && item.State == 1)
                {
                    item.ChatForm.Shows(msgs, DateTime.Now);
                    return backResult;
                }
            }
            backResult.IsSuc = true;
            return backResult;
        }
    }
}
